package com.fafa.yygh.cmn.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.fafa.yygh.cmn.mapper.DictMapper;
import com.fafa.yygh.model.cmn.Dict;
import com.fafa.yygh.vo.cmn.DictEeVo;
import org.springframework.beans.BeanUtils;

/**
 * @author Sire
 * @version 1.0
 * @date 2022-02-08 21:08
 */
public class DictListener extends AnalysisEventListener<DictEeVo> {
    DictMapper dictMapper = null;

    public DictListener(DictMapper dictMapper) {
        this.dictMapper = dictMapper;
    }

    /**
     * 从第二行开始读取内容，每读取一行就将其添加到数据库中
     * 个人感觉这个写法不太好（慢），后期会优化
     */
    @Override
    public void invoke(DictEeVo dictEeVo, AnalysisContext analysisContext) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictEeVo, dict);
        dictMapper.insert(dict);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
